package com.seeyon.apps.gkcwplugin.controller;

import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;

import com.seeyon.apps.gkcwplugin.manager.DealSubjectManager;
import com.seeyon.apps.gkcwplugin.manager.SyncZDManager;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.controller.BaseController;

public class SyncZDController extends BaseController{
	private static final Log logger=LogFactory.getLog(SyncZDController.class);
	private SyncZDManager syncZDManager=(SyncZDManager) AppContext.getBean("syncZDManager");
	private DealSubjectManager dealSubjectManager=(DealSubjectManager)AppContext.getBean("dealSubject");
	public ModelAndView index(HttpServletRequest request, HttpServletResponse response) throws Exception {
		//初次同步字典数据，初始化数据，后续为定时任务定时获取
		//部门对应科目字典可根据客户需求手动执行
		Date date=new Date();
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		logger.info("---------------进入SyncZDController类index方法,time:"+sf.format(date));
		
		String sessionId=syncZDManager.systemInOut();
		logger.info("----------------sessionId:"+sessionId);
		if (sessionId!=null&&!"".equals(sessionId)&&!"null".equals(sessionId)) {
			//syncZDManager.syncContactUnit(sessionId,false);
			logger.info("-------------------1111");
			//syncZDManager.syncDepartment(sessionId,false);
			logger.info("-------------------2222");
			//syncZDManager.syncPersonnel(sessionId,false);
			logger.info("-------------------3333");
			syncZDManager.syncBankAccounts(sessionId,true);
			logger.info("-------------------4444");
			//syncZDManager.syncSubject(sessionId,false);
			logger.info("-------------------5555");
			//部门对应科目字典
			dealSubjectManager.dealSubject();
			logger.info("-------------------6666");
			logger.info("-------------------SyncZDController-index方法结束");
		}else {
			logger.info("------------------SyncZDController:登录接口返回sessionId为空");
		}
		return null;
	}
}
